$.jfeC.addEditor('TinyMCE', {
    name: "TinyMCEEditor",
    start: function(el, options) {

        var settings = {
            script_url : $.jfeC.settings['tinymce']['path'],
            theme : "advanced",
            plugins : "lists,style,save,advlink,inlinepopups,insertdatetime,paste,nonbreaking,xhtmlxtras,template",
            theme_advanced_buttons1 : "pasteword, bold,italic,underline,strikethrough,|,image,|,bullist,outdent,indent,|,link,unlink,|,removeformat",
            theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_blockformats : "",
			theme_advanced_styles: "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "none",
			document_base_url : $.jfeC.settings['baseURL'],
            body_id :"test",
            auto_focus : el.attr('id'),
            oninit: function(ed) {
                /*
                            todo: better solution than window.setTimeout would be nice. But we've to prevent instant closing.
                            */
                    window.setTimeout(function() { $('#'+el.attr('id')+'_parent').bind('clickoutside', function() {
                        el.trigger('jfeCStop');
                    }) }, 200);
            }
        }

        if($.jfeC.settings['tinymce']['default']) $.extend(settings, $.jfeC.settings['tinymce']['default']);
        if($.type(options['settings']) == 'string' && $.jfeC.settings['tinymce'][options['settings']]) $.extend(settings, $.jfeC.settings['tinymce'][options['settings']]);
        else if($.type(options['settings']) == 'object') $.extend(settings, options['settings']);


        $(el).tinymce(settings);

        return true;
    },
    bindStop: function(e, options) {
        //Has to be done asynchronously in "oninit" callback within the "start" method
        return true;
    },
    stop: function(el, options) {
        var data = {}
        data[options['modelName']] = {};
        data[options['modelName']][options['TinyMCE']['fieldName']] = el.html();
        $.extend(data[options['modelName']], options['TinyMCE']['addData']);

        return {
            action: options['TinyMCE']['action'],
            type: 'ajax',
            data: data
        };
    },
    validationErrors: function(el, options, data) {
        this.finish(el, options, data, false, false);
        return true;
    },
    finish: function(el, options, data, success, response) {
        $('#'+el.attr('id')+'_parent').unbind('clickoutside');
        //todo: replace with old content if unsuccessful
        $(el).tinymce().remove();
        return true;
    }
});